﻿using System;
using System.Configuration;
using System.Globalization;
using System.Windows;

namespace FrontDisplay
{
    public sealed class Configuration : ApplicationSettingsBase 
    {
        [UserScopedSetting]
        [DefaultSettingValue("true")]
        public bool CallUpgrade
        {
            get
            {
                return (bool)this["CallUpgrade"];
            }
            set
            {
                this["CallUpgrade"] = value;
            }
        }

        [UserScopedSetting]
#if !DEBUG
        [DefaultSettingValue("true")]
#else
        [DefaultSettingValue("false")]
#endif
        public bool IsShowMouseCursor
        {
            get
            {
                return (bool)this["IsShowMouseCursor"];
            }
            set
            {
                this["IsShowMouseCursor"] = value;
            }
        }

        [UserScopedSetting]
#if !DEBUG
        [DefaultSettingValue("true")]
#else
        [DefaultSettingValue("false")]
#endif
        public bool IsFullScreen
        {
            get
            {
                return (bool)this["IsFullScreen"];
            }
            set
            {
                this["IsFullScreen"] = value;
            }
        }

        [UserScopedSetting]
//#if !DEBUG
        [DefaultSettingValue("true")]
//#else
//        [DefaultSettingValue("false")]
//#endif
        public bool IsTopmost
        {
            get
            {
                return (bool)this["IsTopmost"];
            }
            set
            {
                this["IsTopmost"] = value;
            }
        }

        [UserScopedSetting]
        [DefaultSettingValue("false")]
        public bool InterceptMouse
		{
			get
			{
			    return (bool)this["InterceptMouse"];
			}
            set
            {
                if ((bool)this["InterceptMouse"] != value)
                {
                    if (value)
                    {
                        FrontDisplay.InterceptMouse.SetMouseHook();
                    }
                    else
                    {
                        FrontDisplay.InterceptMouse.RemoveMouseHook();
                    }
                }
                this["InterceptMouse"] = value;
            }
		}

        [UserScopedSetting]
        [DefaultSettingValue("false")]
        public bool IsAutoChangeTheme
        {
            get
            {
                return (bool)this["IsAutoChangeTheme"];
            }
            set
            {
                if ((bool)this["IsAutoChangeTheme"] != value)
                {
                    ((MainWindow) Application.Current.MainWindow).ChangeThemeTimer.IsEnabled = value;
                }
                this["IsAutoChangeTheme"] = value;
            }
        }

        [UserScopedSetting]
        [DefaultSettingValue("300")]
        public int ChangeThemeInterval
        {
            get
            {
                int interval = (int)this["ChangeThemeInterval"];
                return interval > 1 ? interval : 1;
            }
            set
            {
                if (value < 1) return;
                if ((int)this["ChangeThemeInterval"] != value)
                {
                    ((MainWindow) Application.Current.MainWindow).ChangeThemeTimer.Interval = TimeSpan.FromSeconds(value);
                }
                this["ChangeThemeInterval"] = value;
            }
        }

        [UserScopedSetting]
#if !DEBUG
        [DefaultSettingValue("1")]
#else
        [DefaultSettingValue("0")]
#endif
        public int DefaultMonitor
        {
            get
            {
                int defaultMonitor = (int)this["DefaultMonitor"];
                if ((defaultMonitor < System.Windows.Forms.SystemInformation.MonitorCount) && (defaultMonitor >= 0))
                {
                    return defaultMonitor;
                }
                return 0;
            }
            set
            {
                if (DefaultMonitor != value)
                {
                    this["DefaultMonitor"] = value;
                }
            }
        }

        [UserScopedSetting]
        [DefaultSettingValue("Green")]
        public string Theme
        {
            get
            {
                return (string)this["Theme"];
            }
            set
            {
                this["Theme"] = value;
                ThemeManager.UpdateColors();
            }
        }

        [UserScopedSetting]
        [DefaultSettingValue("Gradient")]
        public string Background
        {
            get
            {
                return (string)this["Background"];
            }
            set
            {
                this["Background"] = value;
                ThemeManager.UpdateBackground();
            }
        }

        [UserScopedSetting]
        [DefaultSettingValue("en")]
        public string Language
        {
            get
            {
                return (string)this["Language"];
            }
            set
            {
                this["Language"] = value;
                Def.Localization.CurrentCulture = new CultureInfo(value);
            }
        }

        [UserScopedSetting]
        public HotkeyInfo ChangeThemeHotkey
        {
            get
            {
                if (this["ChangeThemeHotkey"] == null)
                {
                    return new HotkeyInfo { Win = true, Shift = true, Key = System.Windows.Input.Key.K };
                }
                return (HotkeyInfo)this["ChangeThemeHotkey"];
            }
            set
            {
                this["ChangeThemeHotkey"] = value;
            }
        }

        //[UserScopedSetting]
        //public PluginHotkeyCollection PluginHotkeys
        //{
        //    get
        //    {
        //        if (this["PluginHotkeys"] == null)
        //        {
        //            return new PluginHotkeyCollection();
        //        }
        //        return (PluginHotkeyCollection)this["PluginHotkeys"];
        //    }
        //    set
        //    {
        //        this["PluginHotkeys"] = value;
        //    }
        //}
    }
}
